/**
 * 
 */
package com.roc.web.action;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;

import org.apache.log4j.LogManager;
import org.apache.log4j.Logger;
import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Namespace;
import org.apache.struts2.convention.annotation.ParentPackage;
import org.apache.struts2.convention.annotation.Result;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;

import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;

/**
 * @author RenPengFei
 * 
 *         2011-10-28
 */
@Controller
@Namespace("/test")
@ParentPackage("json-default")
@Scope("prototype")
public class HelloWorldAction extends ActionSupport {

	Logger logger = LogManager.getLogger(this.getClass());

	private String field1 = "str";
	private int[] ints = { 10, 20 };
	private Map map = new HashMap();
	private String customName = "custom";
	
	
	
	
	public JsonTestBean getBean() {
		return bean;
	}

	public void setBean(JsonTestBean bean) {
		this.bean = bean;
	}

	public String getField1() {
		return field1;
	}

	public void setField1(String field1) {
		this.field1 = field1;
	}

	public int[] getInts() {
		return ints;
	}

	public void setInts(int[] ints) {
		this.ints = ints;
	}

	public String getCustomName() {
		return customName;
	}

	public void setCustomName(String customName) {
		this.customName = customName;
	}

	public Map getMap() {
		return map;
	}

	public void setMap(Map map) {
		this.map = map;
	}

	private JsonTestBean bean;
	
	@Action(value = "JSONExample",
			results = { @Result(name = "success",
								type = "json",
								params={"root","bean"}) })
	public String jsonTest() throws ParseException {
		SimpleDateFormat sdf=new SimpleDateFormat("yyyyMMdd");
		map.put("John", "Galt");
		bean = new JsonTestBean("任鹏飞", "26");
		bean.setSex("男");
		bean.setBirthday(sdf.parse("19860325"));
		return SUCCESS;
	}

	@Override
	@Action(value = "hello", results = { @Result(name = "success", location = "/helloWorld.jsp") })
	public String execute() throws Exception {
		String message = "Hello World!中文";
		ActionContext.getContext().put("hello", message);
		logger.debug(message);
		logger.error("UTF-8中文测试");
		return SUCCESS;
	}

	@Action(value = "testDate", results = { @Result(name = "success", location = "/helloWorld.jsp") })
	public String testDate() {

		return SUCCESS;
	}

}
